<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class CompleteController extends Controller
{
    //遍历状态为4的订单
    public function index(Request $request)
    {
    	$name = '';
        if($request->has('name')){
            $name = $request->input('name');
        }
        $list = DB::select("select * from `receive_address` inner join `myorder` on `receive_address`.`id` = `myorder`.`reveive_address_id` where status=4 and recycle=1 and myorder.id like '%{$name}%'");
        return view('myorder.complete',['list'=>$list]);
    }
    //放入回收站
    public function destroy($id)
    {
        $row = DB::table('myorder')->where('id',$id)->update(['recycle'=>2]);
        if($row>0){
            return redirect('admin/complete')->with('msg','成功加入回收站');
        }
    }
    public function edit($id)
    {
    	$list = DB::table('myorder')->where('id',$id)->first();
    	return view('myorder.edit',['list'=>$list]);
    }
    //修改备注
     public function update($id,Request $request)
    {
    	$data = $request->except('_token','_method');
    	$row = DB::table('myorder')->where('id',$id)->update($data);
    	if($row>0){

    		return redirect('admin/complete');
    	}else{
            return back()->with('msg','信息无更改');
       }
    }
}